package com.acoreful.acf2java.commons.base;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;

import com.acoreful.acf2java.commons.beans.model.Response;
import com.acoreful.acf2java.commons.beans.response.DataTablesResponse;

public class WebBaseController {
	
	protected Logger logger=LoggerFactory.getLogger(getClass());
	/**
	 * 失败返回
	 * @param data
	 * @return
	 */
	public <T> Response<T> fail(String msg){
		return Response.caughtException(msg);
	}
	/**
	 * 失败返回
	 * @param data
	 * @return
	 */
	public <T> Response<T> fail(int code,String msg){
		return Response.response(code, msg, null);
	}
	/**
	 * 成功返回
	 * @param data
	 * @return
	 */
	public <T> Response<T> successData(T data){
		return Response.success(data);
	}
		
	/**
	 * @param draw
	 * @param page
	 * @return
	 */
	public DataTablesResponse successPageData(Integer draw, Page<?> page){
		return DataTablesResponse.format(draw, page);
	}
	/**
	 * @param draw
	 * @param page
	 * @param error
	 * @return
	 */
	public DataTablesResponse successPageData(Integer draw, Page<?> page,String error){
		return DataTablesResponse.format(draw, page,error);
	}
}
